#include "Clock.h"

Clock::Clock(unsigned char p, BitPointer& c)
{
	counter = Counter<unsigned char>(0, p);
	clock = c;
}

Clock::Clock(Counter<unsigned char>& count, BitPointer& c)
{
	counter = count;
	clock = c;
}

Clock::Clock()
{
	counter = Counter<unsigned char>(0,0);
	clock = BitPointer();
}

void Clock::setPeriod(unsigned char p)
{
	if(counter.getCount() < p)
		counter = Counter<unsigned char>(counter.getCount(), p);
	else
		counter = Counter<unsigned char>(0,p);
}


void Clock::setValue(unsigned char v)
{
	clock.setBit(v);
}

unsigned char Clock::getPeriod()
{
	return counter.getMax();
}

BitPointer Clock::getPointer()
{	
	return clock;
}

void Clock::run()
{
	if(counter.flag()==1)
	{
		//not the bit
		clock.notBit();
		//reset the time for clock.
		counter.resetCount(0);
	}
	counter++;
}

